package com.pshcp.patient.api;

import com.external.ws.szsk.ShenZhouShiKaService;
import com.external.ws.szsk.res.PatientWaitInfo;
import com.external.ws.szsk.res.QueueWaitInfo;
import com.framework.base.ResultBuilder;
import com.framework.base.ResultDTO;
import com.framework.exception.BizException;
import com.framework.logaop.Log;
import com.framework.logaop.LogSourceEnum;
import com.framework.logaop.LogTypeEnum;
import com.framework.tool.CommonTool;
import com.pshcp.domain.model.Patient;
import com.pshcp.patient.domain.searchqueue.ao.PatientWaitListAO;
import com.pshcp.patient.domain.searchqueue.ao.QueueListAO;
import com.pshcp.patient.domain.searchqueue.vo.PatientWaitListVO;
import com.pshcp.patient.domain.searchqueue.vo.QueueListVO;
import com.pshcp.patient.tool.SearchQueueTools;
import com.pshcp.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"患者端-查询-排队叫号"})
@Slf4j
@RestController
@RequestMapping("/api/patient/searchQueue")
public class SearchQueueAPI {

    @Autowired
    private ShenZhouShiKaService shenZhouShiKaService;

    @Autowired
    private PatientService patientService;

    @ApiOperation("患者队列")
    @Log(source = LogSourceEnum.PATIENT_APP, type = LogTypeEnum.SELECT, desc = "患者队列")
    @PostMapping("/info")
    public ResultDTO<List<PatientWaitListVO>> info(@RequestBody PatientWaitListAO listAO) throws BizException {
        Patient patient = patientService.findById(listAO.getPatientId());
        CommonTool.checkObj(patient, "10120002");
        CommonTool.checkObj(patient.getPatientCardNo(),"10210001");
        List<PatientWaitInfo> patientWaitInfos = shenZhouShiKaService.patientWait(patient.getPatientCardNo());
        return ResultBuilder.success(SearchQueueTools.buildPatientListVO(patientWaitInfos));
    }

    @ApiOperation("排队叫号（科室）")
    @Log(source = LogSourceEnum.PATIENT_APP, type = LogTypeEnum.SELECT, desc = "排队叫号（科室）")
    @PostMapping("/queue")
    public ResultDTO<List<QueueListVO>> queue(@RequestBody QueueListAO listAO) throws BizException {
        CommonTool.checkObj(listAO,"10210002");
        CommonTool.checkObj(listAO.getQueueTypeId(),"10210002");
        List<QueueWaitInfo> queueWaitInfos = shenZhouShiKaService.queueWait(listAO.getQueueTypeId());
        return ResultBuilder.success(SearchQueueTools.buildQueueListVO(queueWaitInfos));
    }

}
